package engine.ui
{
	import engine.data.ModelLocator;
	import engine.logic.tips.TipsManage;
	import engine.net.event.CustomMsgEvent;
	import engine.net.messages.CustomToClientFlag;
	import engine.net.messages.CustomToServerFlag;
	import engine.net.mgr.SystemSender;
	import engine.ui.lite.BaseUI;
	
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.StyleSheet;
	
	import newx.StageInfo;
	import newx.com.config.StaticIni;
	import newx.com.control.NxClip;
	import newx.com.control.text.NxLabel;
	import newx.com.control.text.NxText;
	import newx.com.loader.SwfLoader;
	
	/**
	 *	活动导航提示图标 
	 * @author gufan
	 */
	
	public class ActivityGuideUI extends BaseUI
	{
		private static var _self               :ActivityGuideUI;
		
		private var _model                      :ModelLocator;
		/**活动图片显示*/
		public var pic                          :NxClip;
		/**活动内容显示*/
		public var contentTxt1                      :NxLabel;
		/**
		 *服务端人物限制等级 
		 */		
		private var allowLevel:int;
		
		public static function getInstance():ActivityGuideUI
		{
			if(_self == null)
			{
				_self = new ActivityGuideUI();
			}
			return _self;
		}
		
		public function ActivityGuideUI()
		{
			super(false);
		}
		
		override public function Init():void
		{
			_model = ModelLocator.getInstance();
			_model.addEventListener(String(CustomToClientFlag.SERVER_CUSTOMMSG_ACTIVITY_NOTICE),showGuide);            // 接收 服务器打开 导航命令
		}
		
		/*override protected function BeforeShow():void
		{
			addListener();
		}*/
		
		private function showBattleResource(mesNum:Array):void
		{
//			var txtStyle:StyleSheet	=	new StyleSheet();
//			
//			txtStyle.setStyle("a:link"		,{color:"#"+StaticIni.getIniVar("Css_a_Task","link"),textDecoration:"underline"});
//			txtStyle.setStyle("a:visited"	,{color:"#"+StaticIni.getIniVar("Css_a_Task","visited")});
//			txtStyle.setStyle("a:hover"	,{color:"#"+StaticIni.getIniVar("Css_a_Task","hover"),textDecoration:"none"});
			
//			contentTxt1.styleSheet = txtStyle;
			
			var str:String = mesNum[0];
			var serviceOrder:Object = StaticIni.getIniObj("action_" + str);
			var url : String = "res/actors/"+serviceOrder.picName;
			
			SwfLoader.StartLoad(url,null,onComplete);
			
			contentTxt1.htmlStrByBorder = StaticIni.getSwfLangStr(serviceOrder.txtContent);
		}
		
		private function onComplete(val:DisplayObject, pList:Array):void
		{
			var mc:MovieClip;
			mc = (val as MovieClip).getChildAt(0) as MovieClip;
			mc.gotoAndStop(1);
			
			pic.source = Object(mc);
		}
		
		private function addListener():void
		{
			this.buttonMode = true;
			this.addEventListener(MouseEvent.CLICK,showUI);
		}
		
		private function showGuide(e:CustomMsgEvent):void
		{
			addListener();
			
			var arr:Array = e.pList;
			allowLevel  = arr[2];
//			var roleLevel:int;
//			if(ModelLocator.getInstance().scene.Role)
//			{
//				roleLevel = ModelLocator.getInstance().scene.Role.GetProperties("Level");
//			}
			if(arr[1] == 1)					//任务等级限制10级
			{
				var mesNum:Array = e.pList;
				showBattleResource(mesNum);
			}
			else if(arr[1] == 0)
			{
				pic.source = null;
				contentTxt1.htmlStrByBorder = "";
				this.requestClose();
			}
		}
		
		private function showUI(e:MouseEvent):void
		{
			var roleLevel:int = ModelLocator.getInstance().scene.Role.GetProperties("Level");
			if(roleLevel >= allowLevel)
			{
//				UIManage.getInstance().requestOpenUI(CallOfWarUI.getInstance());
			}
			else
			{
				AlertUI.showAlert(StaticIni.getSwfLangStr("MessageUI_Notice"),StaticIni.getSwfLangStr("UIStr_1001464"),AlertUI.OK);
			}
		}
	}
}